package com.goodving.guli.activity;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import com.goodving.guli.R;


public class TabHostMainActivity extends ActivityGroup{

    private TabHost tabHost;//声明一个TabHost对象

    //资源文件
    private Class activitys[]={ScaleActivity.class, CommunityActivity.class,MySettingActivity.class};//跳转的Activity
    private String title[]={"硬实力","活力谷","设置"};//设置菜单的标题
    private int image[]={R.drawable.tab_discovery_btn,R.drawable.tab_rank_btn,R.drawable.tab_more_btn};//设置菜单

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabhost_main);
        initTabView();//初始化tab标签

    }

    private void initTabView() {
        //实例化tabhost
        this.tabHost=(TabHost) findViewById(R.id.mytabhost);

        //由于继承了ActivityGroup，所以需要在setup方法里加入此参数，若继承TabActivity则可省略
        tabHost.setup(this.getLocalActivityManager());

        //创建标签
        for(int i=0;i<activitys.length;i++){
            //实例化一个view作为tab标签的布局
            View view=View.inflate(this, R.layout.tab_layout, null);

            //设置imageview
            ImageView imageView=(ImageView) view.findViewById(R.id.image);
            imageView.setImageDrawable(getResources().getDrawable(image[i]));
            imageView.setLayoutParams(new LinearLayout.LayoutParams(70, 70));
            //设置textview
            TextView textView=(TextView) view.findViewById(R.id.title);
            textView.setText(title[i]);
            textView.setTextSize(13);
            //设置跳转activity
            Intent intent=new Intent(this, activitys[i]);

            //载入view对象并设置跳转的activity
            TabSpec spec=tabHost.newTabSpec(title[i]).setIndicator(view).setContent(intent);

            //添加到选项卡
            tabHost.addTab(spec);
        }

    }
}